package org.ihelpuoo.orm.handler;

import java.lang.reflect.Field;

import org.apache.log4j.Logger;
import org.ihelpuoo.lang.ExceptionUtils;
import org.ihelpuoo.orm.ObjectRule;
import org.ihelpuoo.orm.filter.FieldFilter;

public abstract class FieldHandler
{
	private static Logger		log	= Logger.getLogger(FieldHandler.class);

	protected ObjectProcessor	processor;

	public FieldHandler(ObjectProcessor beanHandler)
	{
		this.processor = beanHandler;
	}

	protected abstract void processWithoutExceptionHandle(ObjectRule r, Field f, Object src,
			Object obj, FieldFilter actived, FieldFilter locked, String prefix) throws Exception;

	public void process(ObjectRule r, Field f, Object src, Object obj, FieldFilter actived,
			FieldFilter locked, String prefix)
	{
		try
		{
			this.processWithoutExceptionHandle(r,f,src,obj,actived,locked,prefix);
		}
		catch (Exception e)
		{
			if (log.isTraceEnabled())
			{
				log.warn("!!! Field: '" + f.getName() + "' Class:'" + r.getType().getName() + "'");
				log.warn(ExceptionUtils.dump(e));
			}
			else if (log.isDebugEnabled())
				log.warn(ExceptionUtils.dumpBrief(e) + "!!! Field: '" + f.getName() + "' Class:'"
						+ r.getType().getName() + "'");
		}
	}
}
